Page({
  data: {
    currentDate: (new Date()).getTime(),
    dateLayerVisible: false,
    houseLayerVisible: false,
    houseList: [
      // { name: '北京西三旗花园1号楼 101' },
      // { name: '北京东村家园3号楼 302' },
      // { name: '北京育新花园3号楼 703' },
      // { name: '北京天通苑北苑8号楼 403' },
    ],
    houseName: '',
    houseId: '',
    name: '小花',
    gender: 1,
    mobile: '13612345678',
    visitDate: '',
  },
  async onLoad() {
    const houseList = await wx.$http.get('/house')
    this.setData({ houseList })
  },
  selectHouse(ev) {
    console.log(ev)
    this.setData({
      houseId: ev.detail.id,
      houseName: ev.detail.name
    })
  },
  selectDate(ev) {
    console.log(ev)
    this.setData({
      dateLayerVisible: false,
      currentDate: ev.detail,
      visitDate: wx.$formatDate(ev.detail)
    })
  },
  openHouseLayer() {
    this.setData({ houseLayerVisible: true })
  },
  closeHouseLayer() {
    this.setData({ houseLayerVisible: false })
  },
  openDateLayer() {
    this.setData({ dateLayerVisible: true })
  },
  closeDateLayer() {
    this.setData({ dateLayerVisible: false })
  },
  async goPassport() {
    const { houseId, name, gender, mobile, visitDate } = this.data
    const res = await wx.$http.post('/visitor', { houseId, name, gender, mobile, visitDate })
    console.log(res)
    wx.redirectTo({
      url: '/visitor_pkg/pages/passport/index?id=' + res.id,
    })
  },
})
